//
// Created by fyniny on 12/23/18.
//
#include "fsys.h"
#include "base.h"
#ifndef SPOOLING_DISPATCHPROCESS_H
#define SPOOLING_DISPATCHPROCESS_H
// 进程id
namespace process_id {
    constexpr auto spooling = 2;
    constexpr auto process1 = 1;
    constexpr auto process2 = 0;
}
// 根据随机数生成的值获取要调度的进程id
#define Dispath(num) \
	(num > 100) ? -1 : \
	(num > 80 )? process_id::spooling : \
	(num > 40 )? process_id::process1 : \
	(num >= 0 )? process_id::process2 : \
	-1
class DispathProcess
{
private:
	// 保存进程
    map<int,Base*> m_process;
public :
	// 装载进程
    void addProcess(int id, Base* base);
    void run();
public:
    DispathProcess();
    ~DispathProcess();
private:
	// 随机调度算法函数
    Base& dispath() ;
    // 判断进程是否全部退出
    bool isAllDied();
public:
	// 根据进程id获取进程实例
    Base* getInstance(int id);
};
#endif //SPOOLING_DISPATCHPROCESS_H
